<?php

/**
* alltosun.com  index.php for newbd
* ============================================================================
* 版权所有 (C) 2009-2014 北京互动阳光科技有限公司，并保留所有权利。
* 网站地址: http://www.alltosun.com
* ----------------------------------------------------------------------------
* 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
* ============================================================================
* Author: 吴松键 (wusj@alltosun.com)
* Date: 15/2/4 下午8:35
*/

class Action
{
    /**
     * ajax 获取快递价格 购物车用
     */
    public function get_express_price()
    {
        $address_id = Request::getParam('address_id', 0);
        $express_id = Request::getParam('express_id', 0);
        $coupon_code = Request::getParam('coupon_code', '');

        $info =  express_helper::get_express_price($express_id, $address_id);

        if (!isset($info['price'])) {
            $info['price'] = 0;
        }
        $info['order_price'] = number_format(cart_helper::get_order_total($info['price'], $coupon_code), 2);

        return $info;
    }

    /**
     * ajax 获取快递价格 订单用
     */
    public function express_price_for_order()
    {
        $order_id = Request::getParam('order_id', 0);
        $address_id = Request::getParam('address_id', 0);
        $express_id = Request::getParam('express_id', 0);

        $info =  express_helper::get_express_price_by_order($order_id, $express_id, $address_id);

        if (!isset($info['price'])) {
            $info['price'] = 0;
        }

        $order_info = _uri('order', $order_id);
        $info['order_price'] = number_format($order_info['price']-$order_info['post_price']+$info['price'], 2);

        return $info;
    }

    /**
     * 通过订单号获取快递信息
     * @return array
     */
    public function ajax_express_info()
    {
        $order_id   = Request::getParam('order_id', 0);
        $service_id = Request::getParam('service_id', 0);
        $order      = Request::getParam('order', 'asc');

        if ($order_id) {
            return express_helper::express_info_by_order($order_id, $order);
        } else {
            if (!$service_id) {
                return array('info'=>'请选择需要查看的快递号');
            }

            $service_info = _uri('refund', $service_id);
            $express_no = $service_info['refund_express'];
            if (!$express_no) {
                return array('当前订单暂未发货');
            }

            $express_code = _uri('express', $service_info['express_id'], 'express_code');

            //$express_code = 'yuantong';
            //$express_no   = '880047680996640772';
            $info = express_helper::express_info($express_code, $express_no, $order);
            if ($info) {
                $info = json_decode($info, true);
                if ($info['status'] == 0) {
                    return array('info'=>$info['message']);
                }

                return array('info'=>'ok', 'json'=>$info);
            }

            return array('info'=>'查询失败，请重试');
        }
        
    }
}